package org.example.springprinciple.scope;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class BeanLifeComponent implements BeanNameAware {

    private UserComponent component;

    public BeanLifeComponent() {
        System.out.println("执行构造函数");
    }

    @Autowired
    public void setUserComponent(UserComponent component) {
        System.out.println("执行了setter方法");
        this.component = component;
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("执行了set方法");
    }

    @PostConstruct
    public void init() {
        System.out.println("执行了init");
    }

    public void use() {
        System.out.println("执行了use");
    }

    @PreDestroy
    public void destroy() {
        System.out.println("执行了destroy");
    }


}
